#include <iostream>

#include "ros/ros.h"
#include "actionlib/client/simple_action_client.h"
#include "demo/MoveAction.h"

void doneCallback(const actionlib::SimpleClientGoalState &state, const demo::MoveResultConstPtr &result, actionlib::SimpleActionClient<demo::MoveAction> *client) {
    ROS_INFO("MoveAction state: %s", state.toString().c_str());
    if (state == state.SUCCEEDED) {
        ros::shutdown();
    }
}

void activeCallback() {
    ROS_INFO("MoveAction active!!!");
}

void feedbackCallback(const demo::MoveFeedbackConstPtr &feedback) {
    ROS_INFO("MoveAction feedback: %d", feedback.get()->distance);
}

int main(int argc, char* argv[]) {
    std::string nodeName = "Client";
    ros::init(argc, argv, nodeName);
    ros::NodeHandle nodeHandle;
    std::string actionName = "move";
    actionlib::SimpleActionClient<demo::MoveAction> &&actionClient = actionlib::SimpleActionClient<demo::MoveAction>(nodeHandle, actionName);
    actionClient.waitForServer();
    demo::MoveGoal goal;
    goal.destination = 5;
    actionClient.sendGoal(goal, boost::bind(&doneCallback, _1, _2, &actionClient), boost::bind(&activeCallback), boost::bind(&feedbackCallback, _1));
    ros::spin();

    return EXIT_SUCCESS;
}